﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[AddComponentMenu("Behavior/SineGroup")]

public class BhvSineGroup : MonoBehaviour
{
    [Header("====== 生命周期 ======")]
    public float period = 4;
    public float periodOffset = 0;
    public float intervalTime = 0;
    public float magnitude = 1.0f;

    public SineBase.Wave wave = SineBase.Wave.sine;
    public BhvSine.Movement movement = BhvSine.Movement.vertical;

    private BhvSine GetBhvSine(Transform item)
    {
        var sine = item.GetComponent<BhvSine>();
        if (sine == null)
        {
            sine = item.gameObject.AddComponent<BhvSine>();
        }
        return sine;
    }
    
    public void Init()
    {
        foreach (Transform item in this.transform)
        {
            var sine = GetBhvSine(item);
            sine.period = this.period;
            sine.periodOffset = this.periodOffset + intervalTime * item.GetSiblingIndex();
            sine.wave = this.wave;
            sine.movement = this.movement;
            sine.magnitude = this.magnitude;
            sine.Init();
        }
    }

    private void Awake()
    {
        this.Init();
    }


}
